<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <script src="/layuiadmin/layui/layui.js"></script>
</head>
<body style="background-color:#fff">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="" class="layui-form layui-form-pane" lay-filter="layui-form-pane" id="sbumitForm">
            <!--
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">支付类型：</label>
                    <div class="layui-input-block">
                        <select name="pay_type" lay-verify="required">
                            <option value="">请选择支付类型</option>
                            <option value="1">钻石</option>
                            <option value="2">宝石</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">应用场景：</label>
                    <div class="layui-input-block">
                        <select name="app_scenarios" lay-verify="required">
                            <option value="">请选择应用场景</option>
                            <option value="1">竞猜</option>
                        </select>
                    </div>
                </div>
            </div>-->
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">筹码面额：</label>
                    <div class="layui-input-block">
                        <input type="text" name="amount"  placeholder="筹码面额"  autocomplete="off" class="layui-input" value="" onkeyup="clearNoNum(this)" />
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">权重：</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort"  placeholder="权重"  autocomplete="off" class="layui-input" value="" onkeyup="clearNoNum(this)"/>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="启用" >
                    <input type="radio" name="status" value="0" title="禁用" checked >
                </div>
            </div>

            <div class="layui-row layui-col-space10"><div class="layui-input-block" style="color: #f0ad4e">注意 权重值越大 显示位置越靠前</div></div>

            <div class="layui-form-item" style="margin-top: 20px">
                <div class="layui-input-block">
                    <span class="layui-btn"  onclick="submitForm()" style="width: 100%">确认添加</span>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['form'], function () {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer;
    });

    function submitForm() {
        layer.confirm('确认要添加吗？', {icon: 6}, function () {
            $.ajax({
                type: "POST", //请求方式
                url: '/admin/chips/add', //请求地址
                dataType: "json", //返回的数据类型
                data: $("#sbumitForm").serialize(), //数据
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.parent.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 5000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                },
                //请求失败
                error: function (e) {
                    layer.msg('添加失败', {icon: 2, time: 5000}, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                }
            });
        });
    }

    function clearNoNum(obj) {
        obj.value = obj.value.replace(/[^\d]/g, "");
        obj.value = obj.value.replace(/^\./g, "");
    }

</script>
</body>

</html>
